package com.zf.bm.common.core.sys.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zf.bm.common.core.sys.entity.Log;
import com.zf.bm.common.core.sys.service.LogService;
import com.zf.bm.common.core.sys.service.RoleService;
import com.zf.bm.common.utils.Collections3;
import com.zf.bm.common.utils.Result;
import com.zf.bm.common.utils.StringUtil;
import com.zf.bm.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;


@RestController
@RequestMapping(value = "${adminPath}/log")
public class LogController extends BaseController {

    @Autowired
    private LogService logService;
    @Autowired
    private RoleService roleService;

    @PostMapping("/list")
    public Result list(@RequestBody(required = false) Log log) {
        log = newInstance(log, Log.class);
        List<String> createBy = null;
        LambdaQueryWrapper<Log> lqw = Wrappers.<Log>lambdaQuery()
                .in(!Collections3.isEmpty(createBy), Log::getCreateBy, createBy)
                .like(StringUtil.isNotBlank(log.getUserName()), Log::getCreateBy, log.getUserName())
                 // GE(">="),see SqlKeyword.class
                .ge(Objects.nonNull(log.getBeginDate()), Log::getCreateDate, log.getBeginDate())
                //  LE("<="),
                .le(Objects.nonNull(log.getEndDate()), Log::getCreateDate, log.getEndDate());
        IPage<Log> page = logService.page(log.getPage(), lqw);
        return new Result(page);
    }
}
